home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 2.iso / dist / fw_gnats.idb / usr / freeware / lib / gnats / contrib / check-db.sh.z / check-db.sh
Linux/UNIX/POSIX Shell Script  |  1999-04-16  |  3KB  |  114 lines

  1. #!/bin/sh
  2. # Check the database for old lock files or index inconsistencies
  3. # Copyright (C) 1993 Free Software Foundation, Inc.
  4. # Contributed by Jonathan Kamens (jik@security.ov.com).
  5. #
  6. # This file is part of GNU GNATS.
  7. #
  8. # GNU GNATS is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. #
  13. # GNU GNATS is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with GNU GNATS; see the file COPYING.  If not, write to
  20. # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. # This script takes no arguments.  It attempts to lock the GNATS
  23. # database for five minutes; if it fails, it sends a mail message
  24. # notifying the administrator of the failure and exits.
  25. # Once the database is locked, the script searches the database for
  26. # lock files that are more than 24 hours old.  Any old lock files are
  27. # reported to the administrator in a mail message.
  28. # After checking for old lock files, it calls gen-index and compares
  29. # the results with gnats-adm/index; any inconsistencies are reported
  30. # to the administrators in a mail message.
  31. # After checking the index file for inconsistencies, the script
  32. # unlocks the database and exits.
  33.  
  34. GNATS_ROOT=xGNATS_ROOTx
  35. GNATS_ADMIN=xGNATS_ADMINx
  36. LIBDIR=xLIBDIRx/gnats
  37. MAIL_AGENT="xMAIL_AGENTx"
  38.  
  39. PATH=$LIBDIR:$GNATS_ROOT/gnats-bin:/bin:/usr/bin; export PATH
  40. TMPDIR=${TMPDIR-/tmp}
  41. TMPFILE=$TMPDIR/gnats-check-db-$$
  42.  
  43. # First, try to lock the database
  44. #
  45.  
  46. i=0
  47. NOTLOCKED=true
  48. while [ $i -lt 30 ]; do
  49.     if $LIBDIR/pr-edit --lockdb; then
  50.         NOTLOCKED=false
  51.         break
  52.     fi
  53.     i=`expr $i + 1`
  54.     sleep 10
  55. done
  56.  
  57. if $NOTLOCKED; then
  58.     $MAIL_AGENT<<EOF
  59. To: $GNATS_ADMIN
  60. Subject: $0: can't lock database
  61.  
  62. Unable to continue database check, because database in
  63. $GNATS_ROOT could not be locked for five minutes.
  64. EOF
  65.     exit 1
  66. fi
  67.  
  68. #
  69. # Now, check for old lock files
  70. #
  71.  
  72. find $GNATS_ROOT -type f -name '[0-9]*.lock' -mtime +1 -print > $TMPFILE
  73. if [ -s $TMPFILE ]; then
  74.     cat - $TMPFILE <<EOF | $MAIL_AGENT
  75. To: $GNATS_ADMIN
  76. Subject: $0: found old lock files
  77.  
  78. The following lock files in the database $GNATS_ROOT
  79. are more than a day old:
  80.  
  81. EOF
  82. fi
  83.  
  84. #
  85. # Now, check for inconsistencies in the index file
  86. #
  87.  
  88. sort -t/ +1n $GNATS_ROOT/gnats-adm/index > $TMPFILE
  89. gen-index --numerical > $TMPFILE.2
  90. if diff $TMPFILE $TMPFILE.2 > $TMPFILE.3; then
  91.     true
  92. else
  93.     cat - $TMPFILE.3 <<EOF | $MAIL_AGENT
  94. To: $GNATS_ADMIN
  95. Subject: $0: possible inconsistencies in database index
  96.  
  97. The following possible inconsistencies were found in
  98. $GNATS_ROOT/gnats-adm/index.
  99.  
  100. Lines prefixed by '<' are from the current index file.  Lines
  101. prefixed by '>' are from a fresh index generated with
  102. $LIBDIR/gen-index.
  103.  
  104. EOF
  105. fi
  106.  
  107. rm -f ${TMPFILE}*
  108. $LIBDIR/pr-edit --unlockdb
  109. exit 0
  110.